function [TLDT,TLDAF,TLDST1,BP_V,new_loc]=InsertBlankRow(TLDT,TLDAF,TLDST1,BP_V,pe_vals,DIM)
% insert unique values into brakpoint array, add zero initialized vector to
%
% the LUTs
%BP_V=break point vector
%pe_vals=values at accelleration pulse end
%TLDT=Table Lookup Data for T(acceleration pulse period) parameter
%TLDAF=Table Lookup Data for AF(applied force) parameter
%DIM=dimension to insert new data into
global RG; % rounding gain
pe_vals=floor(RG*pe_vals)/RG;
if any(BP_V==pe_vals)% then the breakpoint array value already exists, overwrite the LUT data
    new_loc=find(BP_V==pe_vals);
else% we're adding a unique value to the breakpoint array, also add a new value to the LUT
    switch DIM
        case 1
            init_new_data_t=zeros(1,size(TLDT,2),size(TLDT,3),size(TLDT,4));
            init_new_data_af=zeros(1,size(TLDAF,2),size(TLDAF,3),size(TLDAF,4));
            init_new_data_st1=zeros(1,size(TLDST1,2),size(TLDST1,3),size(TLDST1,4));
        case 2
            init_new_data_t=zeros(size(TLDT,1),1,size(TLDT,3),size(TLDT,4));
            init_new_data_af=zeros(size(TLDAF,1),1,size(TLDAF,3),size(TLDAF,4));
            init_new_data_st1=zeros(size(TLDST1,1),1,size(TLDST1,3),size(TLDST1,4));
        case 3
            init_new_data_t=zeros(size(TLDT,1),size(TLDT,2),1,size(TLDT,4));
            init_new_data_af=zeros(size(TLDAF,1),size(TLDAF,2),1,size(TLDAF,4));   
            init_new_data_st1=zeros(size(TLDST1,1),size(TLDST1,2),1,size(TLDST1,4));
        case 4
            init_new_data_t=zeros(size(TLDT,1),size(TLDT,2),size(TLDT,3),1);
            init_new_data_af=zeros(size(TLDAF,1),size(TLDAF,2),size(TLDAF,3),1);  
            init_new_data_st1=zeros(size(TLDST1,1),size(TLDST1,2),size(TLDST1,3),1);
    end
    orig_idx=1:length(BP_V);% indices of existing breakpoint vector
    new_idx=length(BP_V)+1;%index of the new data point to add to BP vector
    [BP_V BPorder]=sort([BP_V pe_vals]);% place new data point into BP vector, return ordered indices
    new_loc=find(BPorder==new_idx);% where is the new data point in the expanded BP vector?
    if new_loc==1% then increase dimension 1 of LUTs by adding zero row to start
        TLDT=cat(DIM, init_new_data_t,TLDT);
        TLDAF=cat(DIM,init_new_data_af, TLDAF);
        TLDST1=cat(DIM,init_new_data_st1, TLDST1);
    elseif new_loc==length(BPorder)% then increase dimension 1 of LUTs by adding zero row to end
        TLDT=cat(DIM,TLDT,init_new_data_t);
        TLDAF=cat(DIM, TLDAF, init_new_data_af);
        TLDST1=cat(DIM, TLDST1, init_new_data_st1);
    else% then increase dimension 1 of LUTs by adding zero row somewhere in the middle
        switch DIM
            case 1
                TSA1=TLDT(1:new_loc-1,:,:,:);% T sub array 1
                TSA2=TLDT(new_loc:size(TLDT,1),:,:,:);% T sub array 2
                AFSA1=TLDAF(1:new_loc-1,:,:,:);% AF sub array 1
                AFSA2=TLDAF(new_loc:size(TLDAF,1),:,:,:);%  
                ST1SA1=TLDST1(1:new_loc-1,:,:,:);% ST1 sub array 1
                ST1SA2=TLDST1(new_loc:size(TLDST1,1),:,:,:);%                
            case 2
                TSA1=TLDT(:,1:new_loc-1,:,:);
                TSA2=TLDT(:,new_loc:size(TLDT,2),:,:);
                AFSA1=TLDAF(:,1:new_loc-1,:,:);
                AFSA2=TLDAF(:,new_loc:size(TLDAF,2),:,:);  
                ST1SA1=TLDST1(:,1:new_loc-1,:,:);
                ST1SA2=TLDST1(:,new_loc:size(TLDST1,2),:,:);%                
            case 3
                TSA1=TLDT(:,:,1:new_loc-1,:);
                TSA2=TLDT(:,:,new_loc:size(TLDT,3),:);
                AFSA1=TLDAF(:,:,1:new_loc-1,:);
                AFSA2=TLDAF(:,:,new_loc:size(TLDAF,3),:);
                ST1SA1=TLDST1(:,:,1:new_loc-1,:);
                ST1SA2=TLDST1(:,:,new_loc:size(TLDST1,3),:);%                
            case 4
                TSA1=TLDT(:,:,:,1:new_loc-1);
                TSA2=TLDT(:,:,:,new_loc:size(TLDT,4));
                AFSA1=TLDAF(:,:,:,1:new_loc-1);
                AFSA2=TLDAF(:,:,:,new_loc:size(TLDAF,4));
                ST1SA1=TLDST1(:,:,:,1:new_loc-1);
                ST1SA2=TLDST1(:,:,:,new_loc:size(TLDST1,4));%                
        end% switch DIM
        TLDT=cat(DIM,TSA1,init_new_data_t,TSA2);
        TLDAF=cat(DIM,AFSA1,init_new_data_af,AFSA2);  
        TLDST1=cat(DIM,ST1SA1,init_new_data_st1,ST1SA2); 
    end% if new_loc==1
end% if any(BP_V==pe_vals)
